package top.vanchor.myblog2back.controller.user.gameCenter;


import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import top.vanchor.myblog2back.entity.BlogGame;
import top.vanchor.myblog2back.service.IBlogGameService;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Ding
 * @since 2022-01-24
 */
@Api("游戏中心控制器")
@RestController
@RequestMapping("/blogGameCenter")
public class BlogGameController {

    @Resource
    private IBlogGameService blogGameService;

    @ApiOperation("获取游戏列表")
    @PostMapping("/getGameList")
    @ResponseBody
    public JSONObject getSearchBlogJson(@RequestBody JSONObject data){
        JSONObject jsonObject = new JSONObject();
        JSONObject jsonData = new JSONObject();
        Integer index = Integer.parseInt(String.valueOf(data.get("pageNum")));
        Integer num = Integer.parseInt(String.valueOf(data.get("num")));
        //传0代表所有，1,2分别查询
        Integer memberType = Integer.parseInt(String.valueOf(data.get("memberType")));
        //''加载所有，否则就模糊查询
        String searchText = String.valueOf(data.get("searchText"));
        PageInfo<BlogGame> list = blogGameService.getGameList(index,num,memberType,searchText);
        jsonData.put("list",list.getList());
        jsonData.put("total",list.getTotal());
        jsonData.put("index",list.getPageNum());
        jsonData.put("num",list.getSize());
        jsonObject.put("data",jsonData);
        jsonObject.put("code",200);
        jsonObject.put("msg","ok");
        return jsonObject;
    }

    @ApiOperation("获取游戏详情")
    @PostMapping("/getGameById")
    @ResponseBody
    public JSONObject getGameById(@RequestBody JSONObject data){
        JSONObject jsonObject = new JSONObject();
        JSONObject jsonData = new JSONObject();
        Integer gameId = Integer.parseInt(String.valueOf(data.get("gameId")));
        BlogGame game = blogGameService.getGameById(gameId);
        jsonData.put("game",game);
        jsonObject.put("data",jsonData);
        jsonObject.put("code",200);
        jsonObject.put("msg","ok");
        return jsonObject;
    }
}
